import http from '@/utils/http/index'

interface searchDto {
  ip: string;
  hostname: string;
  pageNum: number;
  pageSize: number;
}

export interface ClientDto {
  id: string;
  uniqueCode: string;
  assetCode: string;
  ip: string;
  activeMAC: string;
  biosSerial: string;
  mainBoardSerial: string;
  hardDiskSerial: string;
  hostname: string;
  createdAt: string;
  updatedAt: string;
  mapSimilarity: string;
  isOnline: boolean;
  lastMsgTime: string;
}

interface ClientDtoPage {
  list: ClientDto[];
  total: number
}

// 获取客户端分页信息
export const clientPage = (params: searchDto): Promise<ClientDtoPage> => {
  return http.get('ams/client/page', { params })
}

// 获取客户端列表信息
export const clientList = (): Promise<ClientDto[]> => {
  return http.get('ams/client/list')
}

interface AmsClientLog {
  id: string;
  clientId: string;
  cmd: string;
  args: string;
  elapsedTime: string;
  logCode: string;
  logContent: string;
  logCore: string;
  logTime: string;
  createAt: string;
}

// 获取日志详情
export const getLogDetail = (logCode: string, clientId: string): Promise<AmsClientLog> => {
  return http.get('ams/client/LogDetail', { params: { logCode, clientId } })
}


export interface SearchPolicyDto {
  name: string
  resCode: string
}

export interface AmsPolicy {
  id: string
  name: string
  description: string
  resCode: string
  checkField: string
  cmd: string
  args: string
  workspace: string
  timeoutDuration: number
  isBoot: boolean
  isDial: boolean
  isLogin: boolean
  cycle: string
  num: number
  times: number
  startTime: string
  endTime: string
  impactScope: number
  createdAt: string

}

// 策略信息的增删改查
export const getPolicyList = (params: SearchPolicyDto): Promise<AmsPolicy[]> => {
  return http.get('ams/policy/list', { params })
}

export interface AddPolicyDto {
  name: string
  description: string
  resCode: string
  checkField: string
  cmd: string
  args: string
  workspace: string
  timeoutDuration: number
  isBoot: boolean
  isDial: boolean
  isLogin: boolean
  cycle: string
  num: number
  times: number
  startTime: string
  endTime: string
  impactScope: number
}

export const addPolicy = (data: AddPolicyDto) => {
  return http.post('ams/policy/add', data)
}


export interface UpdatePolicyDto {
  id: string
  name: string
  description: string
  resCode: string
  checkField: string
  cmd: string
  args: string
  workspace: string
  timeoutDuration: number
  isBoot: boolean
  isDial: boolean
  isLogin: boolean
  cycle: string
  num: number
  times: number
  startTime: string
  endTime: string
  impactScope: number
}
export const updatePolicy = (data: UpdatePolicyDto) => {
  return http.put('ams/policy/update', data)
}
export const delPolicy = (id: string) => {
  return http.delete('ams/policy/del', { params: { id } })
}

// 插件信息的增删改查

export interface AmsPlugin {
  id: string
  name: string
  description: string
  source: string
  downloadUrl: string
  unTarget: string
  version: string
  md5: string
  zipMd5: string
  checkVersion: boolean
  checkMd5: boolean
  isRequired: boolean
  createdAt: string
}
export interface AddPluginDto {
  name: string
  description: string
  source: string
  downloadUrl: string
  unTarget: string
  version: string
  md5: string
  zipMd5: string
  checkVersion: boolean
  checkMd5: boolean
  isRequired: boolean
}
export interface UpdatePluginDto {
  id: string
  name: string
  description: string
  source: string
  downloadUrl: string
  unTarget: string
  version: string
  md5: string
  zipMd5: string
  checkVersion: boolean
  checkMd5: boolean
  isRequired: boolean
}


export const getPluginList = (): Promise<AmsPlugin[]> => {
  return http.get('ams/plugin/list')
}

export const addPlugin = (data: AddPluginDto) => {
  return http.post('ams/plugin/add', data)
}
export const deletePlugin = (id: string) => {
  return http.delete('ams/plugin/del', { params: { id } })
}
export const updatePlugin = (data: UpdatePluginDto) => {
  return http.put('ams/plugin/update', data)
}
export const getUploadFileUri = () => {
  console.log(http.defaults.baseURL)
  return http.defaults.baseURL + "/ams/plugin/file"
}

// 固资管理

export interface AmsAssetType {
  id: string
  name: string
  description: string
}

export interface AmsAssetCategory {
  id: string
  name: string
  description: string
  parentId: string
}
export interface AssetCategoryNode {
  value: string
  label: string
  description: string
  parentId: string
  children: AssetCategoryNode[]
}

export interface AssetDto {
  id: string
  assetCode: string
  labelType: string
  labelCode: string
  name: string
  typeId: string
  typeName: string
  categoryId: string
  categoryName: string
  tag: string
  description: string
  price: number
  buyAt: string
  expirationAt: string
}

export interface SearchAssetDto {
  assetCode: string
  labelCode: string
  name: string
  pageNum: number;
  pageSize: number;
}

export interface AddAssetDto {
  assetCode: string
  labelType: string
  labelCode: string
  typeId: string;
  name: string;
  categoryId: string;
  tag: string;
  description: string;
}

export const getAssetTypeList = (): Promise<AmsAssetType[]> => {
  return http.get('ams/asset/listType')
}

export const addAssetType = (data: AmsAssetType) => {
  return http.post('ams/asset/addType', data)
}
export const delAssetType = (id: string) => {
  return http.delete('ams/asset/delType', { params: { id } })
}
// getAssetCategoryTree 获取资产分类树形结构
export const getAssetCategoryTree = (): Promise<AssetCategoryNode[]> => {
  return http.get('ams/asset/categoryTree')
}
export const getAssetCategoryList = (): Promise<AmsAssetCategory[]> => {
  return http.get('ams/asset/categoryList')
}

export const addAssetCategory = (data: AmsAssetCategory) => {
  return http.post('ams/asset/addCategory', data)
}
export const delAssetCategory = (id: string) => {
  return http.delete('ams/asset/delCategory', { params: { id } })
}
interface AssetDtoPage {
  list: AssetDto[];
  total: number
}
export const getAssetPage = (params: SearchAssetDto): Promise<AssetDtoPage> => {
  return http.get('ams/asset/page', { params })
}
export const addAsset = (data: AddAssetDto) => {
  return http.post('ams/asset/add', data)
}

export const delAsset = (id: string) => {
  return http.delete('ams/asset/del', { params: { id } })
}

// 耗材逻辑

export interface SearchAssetConsDto {
  assetId: string
  operationType: string
  applicant: string
  pageNum: number
  pageSize: number
}

export interface AssetConsListDto {
  assetId: string
  name: string
  description: string
  num: string
  label: string
  value: string
}

export interface AmsAssetConsLog {
  id: string
  assetId: string
  operationType: string
  num: string
  unit: string
  applicant: string
  operator: string
  admin: string
  createAt: string
  orderCode: string
  notes: string
  picture: string
}

export interface AssetConsLogsDto extends AmsAssetConsLog {
  assetName: string
  assetDesc: string
}

export const getAssetConsPage = (params: SearchAssetDto): Promise<AssetDtoPage> => {
  return http.get('ams/asset/consPage', { params })
}

export const getAssetConsList = (): Promise<AssetConsListDto[]> => {
  return http.get('ams/asset/consList')
}

export interface AssetConsLogsDtoPage {
  list: AssetConsLogsDto[];
  total: number
}
export const getAssetConsLogsPage = (params: SearchAssetConsDto): Promise<AssetConsLogsDtoPage> => {
  return http.get('ams/asset/consLogsPage', { params })
}

export const assetConsLogsAdd = (data: AmsAssetConsLog) => {
  return http.post('ams/asset/consLogsAdd', data)
}
export const getuploadOrderPicUri = () => {
  return http.defaults.baseURL + "/ams/asset/orderPic"
}
// 调用 ocr 获取单据信息
export const callOCR = () => {
  return http.post('ams/asset/ocr')
}
export const getAxiosBaseURL = () => {
  return http.defaults.baseURL
}
